package org.cwnuit.course.dao;

import java.sql.SQLException;
import java.util.List;

import org.cwnuit.course.domain.Coursebox;
import org.cwnuit.course.util.IbatisSqlConfig;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 排课信息管理DAO
 * @author john
 */
public class CourseboxDAO{
	
	/**
	 * 根据排课信息ID获取排课信息
	 * @param objectid
	 * @return
	 */
	public Coursebox getCoursebox(Integer courseid) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		Coursebox coursebox = null;
		try {
			coursebox = (Coursebox) sqlMap.queryForObject("Coursebox.getCoursebox",courseid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return coursebox;
	}
	
	/**
	 * 获取排课ID最大的排课信息
	 * @param objectid
	 */
	public Coursebox getMAXCoursebox(){
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		Coursebox coursebox = null;
		try {
			coursebox = (Coursebox) sqlMap.queryForObject("Coursebox.getMAXCoursebox");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return coursebox;
	}
	
	/**
	 * 获取全部排课信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Coursebox> listCoursebox() {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		List<Coursebox> courseboxList = null;
		try {
			courseboxList = (List<Coursebox>) sqlMap.queryForList("Coursebox.listCoursebox");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return courseboxList;
	}
	
	/**
	 * 删除排课信息
	 * @param objectid
	 * @return
	 */
	public boolean deleteCoursebox(Coursebox coursebox) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.delete("Course.deleteCourse", coursebox);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
}
